
package com.hulk.ratel.common.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author hulk
* @E-mail:29572320@qq.com
* @version Create on:  2017年4月29日 下午9:18:16
* Class description
*/
@Getter
@AllArgsConstructor
public enum Profile {
	
	
	DEV("开发环境"),
	PRO("生产环境"),
	TEST("测试环境");
	

	private String desc;
	


	public static Map<String, Map<String, Object>> toMap() {
		Profile[] ary = Profile.values();
		Map<String, Map<String, Object>> ProfileMap = new HashMap<String, Map<String, Object>>();
		for (int num = 0; num < ary.length; num++) {
			Map<String, Object> map = new HashMap<String, Object>();
			String key = String.valueOf(getEnum(ary[num].name()));
			map.put("value", ary[num].name());
			map.put("desc", ary[num].getDesc());
			ProfileMap.put(key, map);
		}
		return ProfileMap;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List toList() {
		Profile[] ary = Profile.values();
		List list = new ArrayList();
		for (int i = 0; i < ary.length; i++) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("value", ary[i].name());
			map.put("desc", ary[i].getDesc());
			list.add(map);
		}
		return list;
	}
	
	public static Profile getEnum(String value) {
		Profile resultEnum = null;
		Profile[] ProfileAry = Profile.values();
		for (int i = 0; i < ProfileAry.length; i++) {
			if (ProfileAry[i].name().equals(value)) {
				resultEnum = ProfileAry[i];
				break;
			}
		}
		return resultEnum;
	}
	
	/**
	 * 取枚举的json字符串
	 * 
	 * @return
	 */
	public static String getJsonStr() {
		Profile[] enums = Profile.values();
		StringBuffer jsonStr = new StringBuffer("[");
		for (Profile senum : enums) {
			if (!"[".equals(jsonStr.toString())) {
				jsonStr.append(",");
			}
			jsonStr.append("{id:'").append(senum).append("',desc:'").append(senum.getDesc()).append("'}");
		}
		jsonStr.append("]");
		return jsonStr.toString();
	}

}
